import Vue from 'vue'
import VueRouter from 'vue-router'
import Load from '../views/Load.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/load',
    name: 'load',
    component: Load
  },
  {
    path: '/',
    name: 'About',
    redirect: '/about/tab',
    component: () => import('../views/About.vue'),
    children: [
      {
        path: '/about/tab',
        name: 'tab',
        component: () => import ('../views/about/Tab.vue')
      },
      {
        path: '/about/about21',
        name: 'about21',
        component: () => import ('../views/about/About21.vue')
      },
      {
        path: '/about/about31',
        name: 'about31',
        component: () => import ('../views/about/About31.vue')
      },
      {
        path: '/about/about32',
        name: 'about32',
        component: () => import ('../views/about/About32.vue')
      },
      {
        path: '/about/about33',
        name: 'about33',
        component: () => import ('../views/about/About33.vue')
      },
      {
        path: '/about/about34',
        name: 'about34',
        component: () => import ('../views/about/About34.vue')
      },
      {
        path: '/about/about35',
        name: 'about35',
        component: () => import ('../views/about/About35.vue')
      },
      {
        path: '/about/about36',
        name: 'about36',
        component: () => import ('../views/about/About36.vue')
      },
      {
        path: '/about/about41',
        name: 'about41',
        component: () => import ('../views/about/About41.vue')
      },
      {
        path: '/about/about42',
        name: 'about42',
        component: () => import ('../views/about/About42.vue')
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

let isLoad = localStorage.getItem('token')
router.beforeEach((to, from, next)=> {
  if(to.path === '/load') {
    next()
  }else {
    if(isLoad) {
      next()
    }else {
      next('/load')
    }
  }
})

export default router
